{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit NavigationPlugin;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, ActiveX, Classes, ComObj, NavigationManager, Mediate_TLB;

const
  // Press Ctrl+Shift+G to generate a new GUID for each plugin
  //NB: for now all plugins will use this GUID to avoid registration issues
  CLASS_NavigationPlugin: TGUID = '{DEE8ADB6-69E5-405F-809A-842DC8A7C8A1}';

type
  TNavigationPlugin = class(TComObject, IMediatePlugin)
  private
    FNavigation: TAHMNavigationManager;
  protected
    function GetName(out Name: WideString): HResult; stdcall;
    function GetDescription(out Description: WideString): HResult; stdcall;
    function GetDocumentation(out Documentation: WideString): HResult; stdcall;
    function GetVersion(out Version: WideString): HResult; stdcall;
    function GetAuthor(out Author: WideString): HResult; stdcall;
    function OnLoad(const Server: IMediateServer): HResult; stdcall;
    function OnUnload: HResult; stdcall;
    function OnSleep: HResult; stdcall;
    function OnWake: HResult; stdcall;
    function OnUpdate: HResult; stdcall;
    function OnRender: HResult; stdcall;
    function OnConfigure: HResult; stdcall;
    function OnEvent(const EventName: WideString): HResult; stdcall;
    function OnInitialise: HResult; stdcall;
    function OnFinalise: HResult; stdcall;
  end;

implementation

uses ComServ, Dialogs;

function TNavigationPlugin.GetName(out Name: WideString): HResult;
begin
  Name := 'navigation';
  Result := S_OK;
end;

function TNavigationPlugin.GetDescription(out Description: WideString): HResult;
begin
  Description := 'mediate navigation plugin';
  Result := S_OK;
end;

function TNavigationPlugin.GetDocumentation(out Documentation: WideString): HResult;
begin
  Documentation := 'This plugin allows integration with external applications ' +
  'to provide satellite navigation functionality.';
  Result := S_OK;
end;

function TNavigationPlugin.GetVersion(out Version: WideString): HResult;
begin
  Version := '0.1';
  Result := S_OK;
end;

function TNavigationPlugin.GetAuthor(out Author: WideString): HResult;
begin
  Author := '@home media limited';
  Result := S_OK;
end;

function TNavigationPlugin.OnLoad(const Server: IMediateServer): HResult;
begin
  // Create NavigationManager instance
  FNavigation := TAHMNavigationManager.Create(Server);
  Result := S_OK;
end;

function TNavigationPlugin.OnUnload: HResult;
begin
  // Release NavigationManager instance
  FNavigation.Free;
  Result := S_OK;
end;

function TNavigationPlugin.OnSleep: HResult;
begin
  // Not required
  Result := E_NOTIMPL;
end;

function TNavigationPlugin.OnWake: HResult;
begin
  // Not required
  Result := E_NOTIMPL;
end;

function TNavigationPlugin.OnUpdate: HResult;
begin
  // Not required
  Result := E_NOTIMPL;
end;

function TNavigationPlugin.OnRender: HResult;
begin
  // Not required
  Result := E_NOTIMPL;
end;

function TNavigationPlugin.OnConfigure: HResult;
begin
  FNavigation.Configure;
  Result := S_OK;
end;

function TNavigationPlugin.OnEvent(const EventName: WideString): HResult;
begin
  // Not required
  Result := E_NOTIMPL;
end;

function TNavigationPlugin.OnInitialise: HResult;
begin
  FNavigation.Initialise;
  Result := S_OK;
end;

function TNavigationPlugin.OnFinalise: HResult;
begin
  FNavigation.Finalise;
  Result := S_OK;
end;


initialization
  TComObjectFactory.Create(ComServer, TNavigationPlugin, CLASS_MediatePlugin,
    'NavigationPlugin', 'mediate navigation plugin', ciSingleInstance, tmApartment);
end.
